#! /usr/bin/perl

open (IN,"<cipher1.txt") or die "Can't read file: $!"; 
$message = join '', map { chr($_) } split /,/, <IN>;  #read file & convert to ASCII
 
$l = length $message;
for my $key ('aaa' .. 'zzz') {
  $text = $message ^ substr($key x ($l/3 + 1), 0, $l);
  last if $text =~ / the /i;
}
$s += ord($_) for split //, $text;
print "Answer to PE59: $s $text\n";
